<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="../common.jsp"%>
<%@ page import="org.springside.core.Constants"%>
<%@ page import="cn.firstsoft.firstframe.admin.Environment,java.io.*"%>
<%@ page import="java.util.Calendar,java.util.List,java.util.ArrayList"%>

<html>
<head>
<title>管理控制台 - 服务信息</title>
<link href="../style.css" type="text/css" rel=stylesheet>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" background="#FFFFFF">
<script language="javascript"> 
 function showWebLogDetail(){
  if (document.getElementById('webserverLog').style.display == "none") {
    document.getElementById('webserverLog').style.display = "";
    document.getElementById('weblogMore').innerHTML ="隐藏";
  } else {
    document.getElementById('webserverLog').style.display = "none";
    document.getElementById('weblogMore').innerHTML ="更多";
  }
  
 }
  function  showApplicationDetail(){
  if (document.getElementById('applicationLog').style.display == "none") {
    document.getElementById('applicationLog').style.display = "";
    document.getElementById('applicationMore').innerHTML ="隐藏";
  } else {
    document.getElementById('applicationLog').style.display = "none";
    document.getElementById('applicationMore').innerHTML ="更多";
  }
  
 }

</script>
  
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
	<TR>
		<TD class=listViewPaginationTdS1 colSpan=20>
		服务器系统信息

		</TD>
	</TR>

    <TR>
	    <TD class=tabDetailViewDL vAlign=top width="15%">
	    中间件类型:&nbsp;
	    </TD>
	    <TD class=tabDetailViewDF vAlign=top width="75%">
<%
out.println(Environment.getWebServerName());
%>
	    </TD>
        <TD class=tabDetailViewDF vAlign=top width="10%">
	    &nbsp;
	    </TD>
	</TR>
    <TR>
	    <TD class=tabDetailViewDL vAlign=top width="15%">
	    中间件路径:&nbsp;
	    </TD>
	    <TD class=tabDetailViewDF vAlign=top width="75%">
<%
out.println(Environment.getWebServerPath());
%>
	    </TD>
        <TD class=tabDetailViewDF vAlign=top width="10%">
	    &nbsp;
	    </TD>
	</TR>
    <TR>
	    <TD class=tabDetailViewDL vAlign=top width="15%">
	    中间件日志路径:&nbsp;
	    </TD>
	    <TD class=tabDetailViewDF vAlign=top width="75%">
<%
String separator = File.separator;
String logPath = "";


Calendar c = Calendar.getInstance();
String currentDate  = "";
currentDate = ""+c.get(Calendar.YEAR)+"-";
if ((c.get(Calendar.MONTH)+1)>9) {
  currentDate += (c.get(Calendar.MONTH)+1) + "-";
} else {
  currentDate += "0"+(c.get(Calendar.MONTH)+1) + "-";
}

if (c.get(Calendar.DAY_OF_MONTH)>9) {
  currentDate += c.get(Calendar.DAY_OF_MONTH);
} else {
  currentDate += "0"+c.get(Calendar.DAY_OF_MONTH); 
}
String fileName = "file.txt";

if("TOMCAT".equals(Environment.getWebServerName())){
  //D:\KingdeeOA\Tomcat_5.5\logs\catalina.2007-12-29.log 
  logPath = Environment.getWebServerPath() + separator + "logs" + separator ;
  fileName = "catalina."+currentDate+".log";
} else if("APUSIC".equals(Environment.getWebServerName())){
  //E:\kingdee\eas\server\instances\OA\apusic\logs
  logPath = Environment.getWebServerPath() + separator + "logs" + separator ;
  fileName = "apusic.log.0";
}
File lastFile = new File(logPath+fileName);
long currentTime = lastFile.lastModified();

File f = new File(logPath);
String fileNames[] = f.list() ;
List<String> logFiles = new  ArrayList<String>();
if(fileNames !=null){
 for(int i = 0; i<fileNames.length;i++){
  if(( fileNames[i].indexOf("catalina")>-1 ||fileNames[i].indexOf("apusic.log")>-1)
  && !fileNames[i].equalsIgnoreCase(fileName)){
     File tempFile = new File(logPath+fileNames[i]);
     if(tempFile.lastModified() > (currentTime - 1000*60*60*24*5) ){ 
      logFiles.add(fileNames[i]);
      }
   }
 }
}

out.println(logPath+fileName);
%>
	    </TD>
        <TD class=tabDetailViewDF vAlign=top width="10%">
	    <a href="file_download.jsp?filePath=<%=logPath+fileName%>&fileName=<%=fileName%>" tagert="_blank">下载</a>&nbsp;
	<%
	if (logFiles.size() > 0){
	%>
	    <a href="#" onclick="showWebLogDetail();"><span id="weblogMore">更多</span></a>
	<%
	}
	%> 
	    </TD>
	</TR>
	<%
	if (logFiles.size() > 0){
	%>
	<TR id="webserverLog" Style="Display:none">
	    <TD class=tabDetailViewDL vAlign=top width="15%">
	    &nbsp;
	    </TD>
	    <TD class=tabDetailViewDF vAlign=top width="75%">
<%
 for(int i = 0; i<logFiles.size();i++){
   File fff= new File(logPath+(String)logFiles.get(i));
   out.println("<a href=\"file_download.jsp?filePath="+logPath+(String)logFiles.get(i)+"&fileName="+(String)logFiles.get(i)+"\" tagert=\"_blank\">"+(String)logFiles.get(i)+"</a>&nbsp;");
   out.println("&nbsp;&nbsp;");
 }
%>
	    </TD>
        <TD class=tabDetailViewDF vAlign=top width="10%">
	     &nbsp;
	    </TD>
	</TR>
	<%
	}
	%>
	<TR>
	    <TD class=tabDetailViewDL vAlign=top width="15%">
	    应用日志:&nbsp;
	    </TD>
	    <TD class=tabDetailViewDF vAlign=top width="75%">
<%
//\WEB-INF\logs
String filePath2 = request.getRealPath("/") + "WEB-INF" + separator + "logs" + separator ;
out.println(filePath2+ "application.log");

File applicationFile = new File(filePath2);
String applicationNames[] = applicationFile.list() ;
List<String> applicationFiles = new  ArrayList<String>();
 for(int i = 0; i<applicationNames.length;i++){
  if(( applicationNames[i].indexOf("log")>-1 )
  && !applicationNames[i].equalsIgnoreCase("application.log")){
     File tempFile = new File(filePath2+applicationNames[i]);
     if(tempFile.lastModified() > (currentTime - 1000*60*60*24*5) ){ 
       applicationFiles.add(applicationNames[i]);
       }
   }
 }
 
%>
	    </TD>
        <TD class=tabDetailViewDF vAlign=top width="10%">
	    <a href="file_download.jsp?filePath=<%=filePath2+ "application.log"%>&fileName=application.log" tagert="_blank">下载</a>&nbsp;
	<%
	if (applicationFiles.size() > 0){
	%>
	    <a href="#" onclick="showApplicationDetail();"><span id="applicationMore">更多</span></a>
	 <%
	 }
	 %>
	    </TD>
	</TR>
	
<%
	if (applicationFiles.size() > 0){
	%>
	<TR id="applicationLog" Style="Display:none">
	    <TD class=tabDetailViewDL vAlign=top width="15%">
	    &nbsp;
	    </TD>
	    <TD class=tabDetailViewDF vAlign=top width="75%">
<%
 for(int i = 0; i<applicationFiles.size();i++){
   out.println("<a href=\"file_download.jsp?filePath="+filePath2+(String)applicationFiles.get(i)+"&fileName="+(String)applicationFiles.get(i)+"\" tagert=\"_blank\">"+(String)applicationFiles.get(i)+"</a>&nbsp;");
   out.println("&nbsp;&nbsp;");
 }
%>
	    </TD>
        <TD class=tabDetailViewDF vAlign=top width="10%">
	     &nbsp;
	    </TD>
	</TR>
	<%
	}
	%>
	
	<TR>
	    <TD class=tabDetailViewDL vAlign=top width="15%">
	    Log4j属性文件:&nbsp;
	    </TD>
	    <TD class=tabDetailViewDF vAlign=top width="75%">
<%
//\WEB-INF\logs Constants
String filePath3 = System.getProperty("oa_application.config") + separator + "log4j.properties"; 
out.println(filePath3);
%>
	    </TD>
        <TD class=tabDetailViewDF vAlign=top width="10%">
	    <a href="file_download.jsp?filePath=<%=filePath3%>&fileName=log4j.properties" tagert="_blank">下载</a>&nbsp;
	    <a href="logger_log4j.jsp" tagert="_self">修改</a>&nbsp;
	    </TD>
	</TR>
	</TBODY>
</TABLE>
</body>
</html>